using Cirrious.MvvmCross.Application;
using Cirrious.MvvmCross.ExtensionMethods;
using Cirrious.MvvmCross.Interfaces.Plugins;
using Cirrious.MvvmCross.Interfaces.ViewModels;
using Cirrious.MvvmCross.Interfaces.Views;
using Cirrious.MvvmCross.Platform;
using Cirrious.MvvmCross.WinRT.Platform;
using TeaLightV5.Foundation.MvvmCross.Application;
using TeaLightV5.Foundation.UX.WinRT.MvvmCross.Views;
using Windows.UI.Xaml.Controls;

namespace TeaLightV5.Foundation.UX.WinRT.Platform
{
    public abstract class TeaBaseWinRtSetup : MvxBaseWinRTSetup
    {
        protected TeaBaseWinRtSetup(Frame rootFrame)
            : base(rootFrame)
        {
        }

        protected override void InitializeDefaultTextSerializer()
        {
            TeaLightV5.Foundation.MvvmCross.Plugins.Json.PluginLoader.Instance.EnsureLoaded();
        }

        protected override void InitializeViewModelFramework()
        {
            this.RegisterServiceType<IMvxViewModelLoader, TeaViewModelLoader>();
            this.RegisterServiceType<IMvxViewModelLocatorAnalyser, MvxViewModelLocatorAnalyser>();
        }

        protected override IMvxPluginManager CreatePluginManager()
        {
            var toReturn = new MvxLoaderBasedPluginManager();
            var registry = new MvxLoaderPluginRegistry(".WinRT", toReturn.Loaders);
            AddPluginsLoaders(registry);
            return toReturn;
        }

        protected virtual void AddPluginsLoaders(MvxLoaderPluginRegistry loaders)
        {
            // none added by default
        }

        protected override Cirrious.MvvmCross.Views.MvxViewsContainer CreateViewsContainer()
        {
            return new TeaWinRtViewsContainer();
        }

    }
}